package o;

import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
import android.webkit.ConsoleMessage;
import android.webkit.SslErrorHandler;
import android.webkit.ValueCallback;
import android.webkit.WebBackForwardList;
import android.webkit.WebChromeClient;
import android.webkit.WebHistoryItem;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.huawei.appgallery.agwebview.api.ui.IWebViewActivityProtocol;
import com.huawei.appgallery.agwebview.view.WebViewActivity;
import com.huawei.uikit.widget.HwColumnLinearLayout;
import huawei.widget.HwButton;
import java.lang.ref.WeakReference;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.regex.Pattern;
import o.azf.j;

public abstract class azq implements azt, ceh {
    protected ProgressBar ʻ;
    protected c ʻॱ = new c(this);
    public WebView ʼ;
    private azx ʼॱ = null;
    protected LinearLayout ʽ;
    public bah ʽॱ = null;
    protected boolean ʿ = false;
    private String ˈ = null;
    public Context ˊ;
    protected boolean ˊॱ = false;
    public bbe ˋ;
    protected boolean ˋॱ = false;
    protected TextView ˎ;
    protected RelativeLayout ˏ;
    protected boolean ˏॱ = true;
    public Handler ͺ = new d();
    public LinearLayout ॱ;
    protected int ॱˊ = 1;
    protected String ॱˋ;
    protected Map<String, String> ॱˎ;
    public IWebViewActivityProtocol ॱॱ;
    public String ॱᐝ;
    protected LinearLayout ᐝ;
    protected String ᐝॱ;

    public class e extends WebViewClient {
        final /* synthetic */ azq ˋ;

        public e(azq o_azq) {
            this.ˋ = o_azq;
        }

        public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
            if (Logger.ˎ()) {
                azh.ˏ.ˋ("AbstractWebviewDelegate", "onPageStarted, url:" + enx.ॱ(str) + ", currUrl:" + enx.ॱ(this.ˋ.ॱᐝ));
            }
            this.ˋ.ˋॱ = false;
            this.ˋ.ˏ(str);
            this.ˋ.ʻ(str);
            super.onPageStarted(webView, str, bitmap);
        }

        public void onPageFinished(WebView webView, String str) {
            this.ˋ.ʼ.getSettings().setBlockNetworkImage(false);
            String title = webView.getTitle();
            if (dof.ˋ(title) || str.equals(title) || this.ˋ.ॱॱ(title)) {
                title = this.ˋ.ˏॱ().getString(j.ॱॱ);
            }
            this.ˋ.ˊ(title);
            this.ˋ.ˏ(str);
            if (Logger.ˎ()) {
                azh.ˏ.ˋ("AbstractWebviewDelegate", "onPageFinished, currUrl:" + enx.ॱ(this.ˋ.ॱᐝ));
            }
        }

        public void onReceivedError(WebView webView, int i, String str, String str2) {
            String ॱ = enx.ॱ(str2);
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("onReceivedError, failingUrl:").append(ॱ).append(", errorCode:").append(i).append(", description:").append(str);
            azh.ˏ.ˏ("AbstractWebviewDelegate", stringBuilder.toString());
            this.ˋ.ॱˊ = 0;
            this.ˋ.ॱ(i);
            esy.ˊ(ॱ, String.valueOf(i));
        }

        @TargetApi(23)
        public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
            if (Logger.ˎ() && webResourceRequest.getUrl() != null) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("onReceivedError, errorUrl: ").append(enx.ॱ(webResourceRequest.getUrl().toString())).append(", errorCode:").append(webResourceError.getErrorCode()).append(", description:").append(webResourceError.getDescription());
                azh.ˏ.ˏ("AbstractWebviewDelegate", stringBuilder.toString());
            }
            super.onReceivedError(webView, webResourceRequest, webResourceError);
        }

        @TargetApi(23)
        public void onReceivedHttpError(WebView webView, WebResourceRequest webResourceRequest, WebResourceResponse webResourceResponse) {
            String uri = webResourceRequest.getUrl().toString();
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("onReceivedHttpError, errorUrl: ").append(enx.ॱ(uri)).append(", statusCode:").append(webResourceResponse.getStatusCode()).append(", description:").append(webResourceResponse.getReasonPhrase());
            azh.ˏ.ˏ("AbstractWebviewDelegate", stringBuilder.toString());
            if (uri.equals(this.ˋ.ॱᐝ)) {
                this.ˋ.ॱˊ = 0;
                this.ˋ.ॱ(-1);
                esy.ˊ(enx.ॱ(uri), String.valueOf(webResourceResponse.getStatusCode()));
                return;
            }
            super.onReceivedHttpError(webView, webResourceRequest, webResourceResponse);
        }

        public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
            if (aze.ˊ()) {
                sslErrorHandler.proceed();
                azh.ˏ.ˏ("AbstractWebviewDelegate", "onReceivedSslError keep loading");
                return;
            }
            sslErrorHandler.cancel();
            azh.ˏ.ˏ("AbstractWebviewDelegate", "onReceivedSslError stop loading");
        }
    }

    public class a extends WebChromeClient {
        final /* synthetic */ azq ॱ;

        public a(azq o_azq) {
            this.ॱ = o_azq;
        }

        public void onProgressChanged(WebView webView, int i) {
            if (!this.ॱ.ˊ() && this.ॱ.ʻ != null) {
                if (i == 100) {
                    this.ॱ.ʻ.setVisibility(8);
                } else {
                    this.ॱ.ʻ.setVisibility(0);
                    this.ॱ.ʻ.setProgress(i);
                }
                if (this.ॱ.ʼ.getVisibility() == 8 && i >= 80 && !this.ॱ.ˋॱ && this.ॱ.ॱˊ == 1) {
                    this.ॱ.ˋॱ = true;
                    this.ॱ.ˊˊ();
                }
            }
        }

        public void onReceivedTitle(WebView webView, String str) {
            if (this.ॱ.ॱॱ(str)) {
                str = this.ॱ.ˏॱ().getString(j.ॱॱ);
            }
            this.ॱ.ˊ(str);
        }

        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            return true;
        }

        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> valueCallback, FileChooserParams fileChooserParams) {
            if (this.ॱ.ʼॱ != null) {
                this.ॱ.ʼॱ.ॱ(this.ॱ.ˏॱ(), webView, valueCallback, fileChooserParams);
            }
            return true;
        }
    }

    static class b implements Runnable {
        private WeakReference<azq> ˋ;

        public b(azq o_azq) {
            this.ˋ = new WeakReference(o_azq);
        }

        public void run() {
            azq o_azq = (azq) this.ˋ.get();
            if (o_azq == null) {
                azh.ˏ.ˏ("AbstractWebviewDelegate", "UpdateWebViewStatusRunnable delegate null");
            } else if (o_azq.ˋॱ && o_azq.ʼ.getVisibility() == 8 && o_azq.ॱˊ == 1) {
                o_azq.ʼ.setVisibility(0);
            }
        }
    }

    protected class c {
        final /* synthetic */ azq ॱ;

        protected c(azq o_azq) {
            this.ॱ = o_azq;
        }

        private void ˊ() {
            try {
                Context ˏॱ = this.ॱ.ˏॱ();
                if (ˏॱ instanceof Activity) {
                    ActionBar actionBar = ((Activity) ˏॱ).getActionBar();
                    if (actionBar != null) {
                        actionBar.hide();
                    }
                }
                this.ॱ.ॱ = (LinearLayout) this.ॱ.ˏ.findViewById(o.azf.a.ˏ);
                this.ॱ.ˎ = (TextView) this.ॱ.ˏ.findViewById(o.azf.a.ᐝॱ);
                this.ॱ.ˋ = new bbe((LinearLayout) this.ॱ.ˏ.findViewById(o.azf.a.ॱॱ), this.ॱ.ʼ, this.ॱ.ˎ);
                this.ॱ.ॱ.setOnClickListener(new OnClickListener(this) {
                    final /* synthetic */ c ॱ;

                    {
                        this.ॱ = r1;
                    }

                    public void onClick(View view) {
                        this.ॱ.ॱ.ᐝ();
                    }
                });
            } catch (Throwable e) {
                azh.ˏ.ˊ("AbstractWebviewDelegate", "initTitle error", e);
            }
        }

        public void ˎ(String str) {
            if (!"*#title*#".equals(str)) {
                if (dof.ˋ(str)) {
                    str = this.ॱ.ˏॱ().getString(j.ॱॱ);
                }
                if (this.ॱ.ˎ != null) {
                    this.ॱ.ˎ.setText(str);
                }
            }
        }
    }

    static class d extends Handler {
        private d() {
        }
    }

    public abstract void ʽ(String str);

    public void ˎ(azx o_azx) {
        this.ʼॱ = o_azx;
    }

    protected void ॱ(int i) {
        if (this.ʼ != null) {
            this.ʼ.setVisibility(8);
        }
        if (this.ʻ != null) {
            this.ʻ.setIndeterminate(false);
        }
        if (this.ᐝ != null) {
            TextView textView = (TextView) this.ᐝ.findViewById(o.azf.a.ॱᐝ);
            HwColumnLinearLayout hwColumnLinearLayout = (HwColumnLinearLayout) this.ᐝ.findViewById(o.azf.a.ॱˎ);
            HwButton hwButton = (HwButton) this.ᐝ.findViewById(o.azf.a.ॱˊ);
            if (i == -2) {
                textView.setText(j.ˋॱ);
                ˎ(hwColumnLinearLayout, hwButton, 0);
            } else if (i == 1000) {
                ˊ(ˏॱ().getString(j.ॱ));
                textView.setText(j.ˊ);
                ˎ(hwColumnLinearLayout, hwButton, 8);
            } else {
                textView.setText(j.ʻ);
                ˎ(hwColumnLinearLayout, hwButton, 0);
            }
            if (this.ˎ != null && TextUtils.isEmpty(this.ˎ.getText())) {
                ˊ(ˏॱ().getString(j.ॱॱ));
            }
            this.ᐝ.setVisibility(0);
            if (this.ʽ != null) {
                LayoutParams layoutParams = this.ᐝ.getLayoutParams();
                if (layoutParams instanceof RelativeLayout.LayoutParams) {
                    ((RelativeLayout.LayoutParams) layoutParams).addRule(2, this.ʽ.getId());
                }
            }
        }
    }

    private void ˎ(HwColumnLinearLayout hwColumnLinearLayout, HwButton hwButton, int i) {
        if (hwColumnLinearLayout != null) {
            hwColumnLinearLayout.setVisibility(i);
        } else {
            hwButton.setVisibility(i);
        }
    }

    protected void ˏ(String str) {
        this.ॱᐝ = str;
    }

    protected void ˊ(String str) {
        this.ʻॱ.ˎ(str);
    }

    protected boolean ॱॱ(String str) {
        try {
            return Pattern.compile("^(http://|https://)", 2).matcher(str).find();
        } catch (Exception e) {
            return false;
        }
    }

    private void ˊˊ() {
        this.ͺ.postDelayed(new b(this), 300);
    }

    public boolean ˊ() {
        Context ˏॱ = ˏॱ();
        if (ˏॱ instanceof Activity) {
            return ((Activity) ˏॱ).isFinishing();
        }
        return true;
    }

    public boolean ˊ(Context context, IWebViewActivityProtocol iWebViewActivityProtocol) {
        if (context == null || iWebViewActivityProtocol == null) {
            azh.ˏ.ˊ("AbstractWebviewDelegate", "check context or request null");
            return false;
        }
        this.ˊ = context;
        this.ॱॱ = iWebViewActivityProtocol;
        this.ॱˋ = iWebViewActivityProtocol.getUrl();
        this.ॱˎ = iWebViewActivityProtocol.getBusinessParams();
        this.ᐝॱ = iWebViewActivityProtocol.getMethod();
        return true;
    }

    public void ॱ(Context context, IWebViewActivityProtocol iWebViewActivityProtocol) {
    }

    public void ˏ(Context context, IWebViewActivityProtocol iWebViewActivityProtocol) {
        ˎ();
        ˋ();
        this.ᐝ.setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ azq ॱ;

            {
                this.ॱ = r1;
            }

            public void onClick(View view) {
                if (this.ॱ.ॱˊ != 2 && this.ॱ.ʼ != null && this.ॱ.ᐝ != null && doo.ˊ(this.ॱ.ˏॱ())) {
                    this.ॱ.ॱˊ = 1;
                    this.ॱ.ॱ();
                }
            }
        });
        ˏ();
    }

    protected void ˏ() {
        enz.ˊ(this.ᐝ, ˏॱ());
    }

    protected void ॱ() {
        WebBackForwardList copyBackForwardList = this.ʼ.copyBackForwardList();
        if (copyBackForwardList == null || copyBackForwardList.getSize() == 0) {
            ʽ(this.ॱˋ);
        } else if (this.ʽॱ != null) {
            this.ʽॱ.ˎ(this.ʼ);
        }
        this.ᐝ.setVisibility(8);
    }

    protected void ˎ() {
        this.ʻॱ.ˊ();
    }

    public void ॱ(Activity activity) {
        if (activity instanceof WebViewActivity) {
            cgv.ˋ(activity, o.azf.c.ˎ, o.dky.d.ˏॱ);
        }
    }

    public void ˋ() {
        WebSettings settings = this.ʼ.getSettings();
        settings.setCacheMode(2);
        settings.setJavaScriptEnabled(this.ˏॱ);
        settings.setAllowFileAccess(this.ˊॱ);
        settings.setDatabaseEnabled(true);
        settings.setAllowContentAccess(false);
        settings.setDomStorageEnabled(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setSavePassword(false);
        settings.setSupportZoom(true);
        settings.setBuiltInZoomControls(true);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        ˋˊ();
        settings.setMixedContentMode(1);
        this.ʼ.requestFocus();
        settings.setDisplayZoomControls(false);
        settings.setAllowFileAccessFromFileURLs(false);
        settings.setAllowUniversalAccessFromFileURLs(false);
        this.ʼ.removeJavascriptInterface("accessibility");
        this.ʼ.removeJavascriptInterface("accessibilityTraversal");
        this.ʼ.removeJavascriptInterface("searchBoxJavaBridge_");
    }

    private void ˋˊ() {
        if (this.ʼ != null) {
            WebSettings settings = this.ʼ.getSettings();
            settings.setUserAgentString(settings.getUserAgentString() + ॱॱ());
        }
    }

    protected String ॱॱ() {
        return "";
    }

    public void ʽ() {
        ʿ();
    }

    public void ᐝ() {
        ˋॱ();
    }

    public boolean ʼ() {
        return true;
    }

    public boolean ˋ(int i, String[] strArr, int[] iArr) {
        PermissionChecker.ˎ(this, i, strArr, iArr);
        return true;
    }

    public void ˏ(int i, int i2) {
        if (i2 == 0) {
            ˊॱ();
        }
    }

    public int ʻ() {
        return o.azf.d.ॱ;
    }

    protected void ˏ(LinearLayout linearLayout) {
    }

    public void ˎ(View view) {
        this.ˏ = (RelativeLayout) view.findViewById(o.azf.a.ॱˋ);
        if (this.ˏ != null) {
            azb.ˏ(this.ˏ);
        }
        this.ʻ = (ProgressBar) view.findViewById(o.azf.a.ˊ);
        if (this.ʻ != null) {
            azb.ˏ(this.ʻ);
        }
        this.ʼ = (WebView) view.findViewById(o.azf.a.ॱ);
        if (this.ʼ != null) {
            azb.ˏ(this.ʼ);
        }
        this.ᐝ = (LinearLayout) view.findViewById(o.azf.a.ʾ);
        if (this.ᐝ != null) {
            azb.ˏ(this.ᐝ);
        }
        ˏ((LinearLayout) view.findViewById(o.azf.a.ˊॱ));
    }

    public Context ˏॱ() {
        if (this.ˊ == null) {
            return ContentManager.getInstant().getContext();
        }
        return this.ˊ;
    }

    public void ʻ(String str) {
    }

    public boolean ͺ() {
        return ˏॱ() instanceof Activity;
    }

    public void ᐝ(String str) {
        if (this.ʼ != null && this.ॱॱ != null) {
            this.ॱॱ.setUrl(str);
            ʽ(str);
        }
    }

    public void ˊॱ() {
        if (this.ʼ != null) {
            WebBackForwardList copyBackForwardList = this.ʼ.copyBackForwardList();
            if (copyBackForwardList != null) {
                WebHistoryItem itemAtIndex = copyBackForwardList.getItemAtIndex(copyBackForwardList.getCurrentIndex());
                if (itemAtIndex != null) {
                    String url = itemAtIndex.getUrl();
                    this.ʼ.setVisibility(0);
                    this.ᐝ.setVisibility(8);
                    ʽ(url);
                }
            }
        }
    }

    public void ॱˊ() {
        ˋॱ();
    }

    public void ˋॱ() {
        if (!this.ʽॱ.ˏ(this.ˊ)) {
            if (this.ʼ == null || !this.ʼ.canGoBack()) {
                ॱᐝ();
            } else if (doo.ˊ(ˏॱ())) {
                if (this.ᐝ != null && this.ᐝ.getVisibility() == 0) {
                    this.ᐝ.setVisibility(8);
                }
                this.ॱˊ = 1;
                this.ʼ.goBack();
            } else {
                ॱᐝ();
            }
        }
    }

    protected void ॱᐝ() {
        if (ͺ()) {
            ʻॱ().finish();
        }
    }

    protected Activity ʻॱ() {
        if (ͺ()) {
            return (Activity) ˏॱ();
        }
        throw new IllegalStateException("The context isn't Activity!");
    }

    public void ॱˋ() {
        try {
            if (this.ʻ != null) {
                this.ʻ.setIndeterminate(false);
            }
            if (this.ʿ) {
                if (this.ʼ != null) {
                    this.ʼ.getClass().getMethod("onResume", new Class[0]).invoke(this.ʼ, (Object[]) null);
                }
                this.ʿ = false;
            }
        } catch (Exception e) {
            azh.ˏ.ˏ("AbstractWebviewDelegate", "onResume error");
        }
        ᐝॱ();
    }

    protected LinkedHashMap ॱˎ() {
        LinkedHashMap linkedHashMap = new LinkedHashMap(4);
        if (epr.ˎ().ˏ() != null) {
            linkedHashMap.put("third_id", epr.ˎ().ˏ());
        }
        linkedHashMap.put("page_id", enx.ॱ(this.ॱᐝ));
        if (ͺ()) {
            linkedHashMap.put("service_type", Integer.valueOf(dgm.ˎ(ʻॱ())));
        } else {
            azh.ˏ.ˏ("AbstractWebviewDelegate", "Not activity context.");
        }
        linkedHashMap.put("user_agent", ॱॱ().trim());
        return linkedHashMap;
    }

    protected void ᐝॱ() {
        dgh.ˏ(ʾ(), ॱˎ());
    }

    protected void ʼॱ() {
        dgh.ॱ(ʾ(), ॱˎ());
    }

    protected String ʾ() {
        return "AbstractWebviewDelegate";
    }

    public void ˈ() {
        try {
            if (this.ʼ != null) {
                this.ʼ.getClass().getMethod("onPause", new Class[0]).invoke(this.ʼ, (Object[]) null);
                this.ʿ = true;
            }
        } catch (Exception e) {
            azh.ˏ.ˏ("AbstractWebviewDelegate", "onPause error");
        }
        ʼॱ();
    }

    public void ˎ(Configuration configuration) {
        if (this.ʼ != null) {
            this.ʼ.onResume();
        }
        if (this.ˋ != null) {
            this.ˋ.ʽ();
        }
    }

    protected void ʿ() {
        this.ʿ = false;
        if (this.ʼ != null) {
            ˊˋ();
            this.ʼ.clearHistory();
            this.ʼ.destroy();
        }
        this.ˊ = null;
    }

    private void ˊˋ() {
        try {
            ViewParent parent = this.ʼ.getParent();
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(this.ʼ);
                this.ʼ.removeAllViews();
            }
        } catch (Exception e) {
            azh.ˏ.ˏ("AbstractWebviewDelegate", "removeWebView error");
        }
    }

    public void ˋ(Context context, String str, int i) {
        evk.ˋ(context, str, 0).ˋ();
    }

    public String ʽॱ() {
        return this.ˈ;
    }

    public void ʼ(String str) {
        this.ˈ = str;
    }
}
